package com.geostar.constructionland.index.controller;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geostar.constructionland.index.entity.AddHookIndex;
import com.geostar.constructionland.index.entity.model.AddHookIndexModel;
import com.geostar.constructionland.index.entity.model.InsertAddHookIndexModel;
import com.geostar.constructionland.index.entity.model.InsertInxStogAcotModel;
import com.geostar.constructionland.index.entity.server.ServerResponse;
import com.geostar.constructionland.index.entity.vo.SelInxOutStorageAcotData;
import com.geostar.constructionland.index.service.AddHookIndexService;
import com.geostar.constructionland.index.util.FormatUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author df
 * @since 2020-2-4 10:07
 **/
@RestController
@RequestMapping("/addHookIndex")
@Api(tags = "增存挂钩指标相关接口")
public class AddHookIndexController {
    @Resource
    AddHookIndexService addHookIndexService;

    @ApiOperation(value = "获取增存挂钩指标信息列表",notes = "获取增存挂钩指标信息列表，必须设置分页参数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "页码",required = true),
            @ApiImplicitParam(name = "pagesize",value = "页数",required = true),
            @ApiImplicitParam(name = "divisionCode",value = "地级市编码 djs"),
            @ApiImplicitParam(name = "keyWord",value = "项目名称 xmmc 或者 入库id rkid"),
            @ApiImplicitParam(name = "sortOrder",value = "排序类型 "),
            @ApiImplicitParam(name = "sortName",value = "排序字段 "),
            @ApiImplicitParam(name = "indexStatus",value = "指标状态 "),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public Map<String,Object> queryAddHookIndexList(@Valid AddHookIndexModel addHookIndexModel){
        IPage<Map<String,String>> mapData=addHookIndexService.queryAddHookIndexList(addHookIndexModel);
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("data",mapData.getRecords());
        map.put("total",mapData.getTotal());
        return map;
    }


    @ApiOperation(value = "根据id获取增存挂钩指标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "入库id",required = true),
    })
    @PostMapping(value = "/query/{id}")
    @ResponseBody
    public AddHookIndex queryAddHookIndexById(@PathVariable String id){
        return addHookIndexService.queryAddHookIndex(id);

    }


    @ApiOperation(value = "添加或修改增存挂钩指标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键id zbid"),
            @ApiImplicitParam(name = "divisionCode",value = "地级市 djs"),
            @ApiImplicitParam(name = "divisionName",value = "地级市名称 djsmc"),
            @ApiImplicitParam(name = "wingName",value = "县市区（行政区划代码）xsqmc"),
            @ApiImplicitParam(name = "projectName",value = "项目名称 xmmc"),
            @ApiImplicitParam(name = "approvalAuthority",value = "批准机关 pzjg"),
            @ApiImplicitParam(name = "approvalTime",value = "批准时间 pzsj"),
            @ApiImplicitParam(name = "approvalNum",value = "批复文号 pfwh"),
            @ApiImplicitParam(name = "approvalArea",value = "批准面积 pzmj"),
            @ApiImplicitParam(name = "buildLandAdd",value = "新增建设用地(BigDecimal) xzjsyd"),
            @ApiImplicitParam(name = "agclLand",value = "农用地(BigDecimal) nyd"),
            @ApiImplicitParam(name = "farmland",value = "耕地(BigDecimal) gd"),
            @ApiImplicitParam(name = "isCompensationScheme",value = "是否至今未实施征地补偿安置方案 is_ss"),
            @ApiImplicitParam(name = "areConsistent",value = "现场地类与批准前是否一致 is_yz"),
            @ApiImplicitParam(name = "landThatDepartment",value = "现场地类认定部门 xcdlrdbm"),
            @ApiImplicitParam(name = "remark",value = "备注 bz"),
    })
    @PostMapping(value = "/insertOrUpdate")
    @ResponseBody
    public ServerResponse insertOrUpdateAddHookIndex(@Valid InsertAddHookIndexModel insertAddHookIndexModel){
        int result = addHookIndexService.addOrUpdateAddHookIndex(insertAddHookIndexModel);
        if(result>0){
           return ServerResponse.createBySuccess();
        }
        return ServerResponse.createByErrorMessage("操作失败！！！！！！！！");
    }

    @ApiOperation(value = "根据id集合删除增存挂钩指标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "增存挂钩id集合",required = true),
    })
    @PostMapping(value = "/delete")
    @ResponseBody
    public ServerResponse deleteAddHookIndexByIds(@RequestParam(name = "ids") String ids){
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        if(StringUtils.isBlank(ids)) {
           return  ServerResponse.createByErrorMessage("传入参数有误：增存挂钩指标id集合数值错误！");
        }
        int result = addHookIndexService.delAddHookIndexByIds(FormatUtils.getStringByList(ids));
        if(result>0){
            return serverResponse;
        }
        return  ServerResponse.createByErrorMessage("删除失败！！！！！！！！");

    }


}
















